//
//  WebViewController.m
//  YouRBook
//
//  Created by allting on 12. 9. 15..
//  Copyright (c) 2012년 allting. All rights reserved.
//

#import "WebViewController.h"

#define kDEFAULT_URL		@"http://m.appcenter.kr"

@interface WebViewController ()

@end

@implementation WebViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
	CGRect frame = [self calculateWebViewFrame];
	UIWebView* webView = [[UIWebView alloc]initWithFrame:frame];
	webView.delegate = self;
	
	NSURLRequest* request = [NSURLRequest requestWithURL:[self requestURL]];
	[webView loadRequest:request];
	
	[self.view addSubview:webView];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Public methods
-(NSURL*)requestURL{
	return [NSURL URLWithString:kDEFAULT_URL];
}

-(void)back{
	if([self.webView canGoBack])
		[self.webView goBack];
}

-(BOOL)canGoBack{
	return [self.webView canGoBack];
}

-(BOOL)updateState{
	return NO;
}

#pragma mark - Private methods
-(CGRect)calculateWebViewFrame{
	CGRect bounds = self.view.bounds;
	CGRect tabRect = self.tabBarController.tabBar.frame;
	
	bounds.size.height -= CGRectGetHeight(tabRect);
	return bounds;
}

#pragma mark - UIWebView delegate
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
	
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
	return YES;
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
	[self updateState];
}

- (void)webViewDidStartLoad:(UIWebView *)webView
{
	
}

@end
